package threading;


class FlagThread extends Thread {

    public static boolean isInterrupt = false;
    @Override
    public void run() {
        while (!isInterrupt) {

        }
    }
}


public class Demo14 {

    private static volatile boolean isInterrupt = false;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("0");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t1.start();
        Thread t2 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t2.start();
        Thread t3 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t3.start();
        Thread t4 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("3");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t4.start();
        Thread t5 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("4");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t5.start();
        Thread t6 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("5");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t6.start();
        Thread t7 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("6");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t7.start();
        Thread t8 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("7");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t8.start();
        Thread t9 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("8");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t9.start();
        Thread t10 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("9");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t10.start();
        Thread t11 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("10");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t11.start();
        Thread t12 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("11");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t12.start();
        Thread t13 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("12");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t13.start();
        Thread t14 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("13");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t14.start();
        Thread t15 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("14");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t15.start();
        Thread t16 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("15");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t16.start();
        Thread t17 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("16");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t17.start();
        Thread t18 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("17");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t18.start();
        Thread t19 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("18");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t19.start();
        Thread t20 = new Thread(() -> {
            while (!isInterrupt) {
                System.out.println("19");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t20.start();



        Thread.sleep(10);
        System.out.println("OK!");
        isInterrupt = true;





    }
}
